﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using MongoDB.Driver.Builders;

namespace wheel.Repositories
{
    public class WheelOfFortuneUserInfo
    {
        MongoCollection<WheelofFortuneScore> collection;
        public WheelOfFortuneUserInfo()
        {
            var server = MongoServer.Create(System.Configuration.ConfigurationManager.AppSettings["MongoDBConnectionString"]);
            var database = server.GetDatabase("WheelOfFortune");
            collection = database.GetCollection<WheelofFortuneScore>("entities");
        }

        public void Add(WheelofFortuneScore newScore)
        {
            collection.Insert(newScore);
        }

        public List<WheelofFortuneScore> GetTopScore(int NoOfRecords)
        {
            return collection.FindAll().SetSortOrder(SortBy.Descending("Score")).Take(NoOfRecords).ToList();
        }

        public void ClearScores()
        {
            collection.RemoveAll();
        }
    }


    public class WheelofFortuneScore
    {
        public ObjectId Id { get; set; }
        public string UserName { get; set; }
        public string WordId { get; set; }
        public decimal Score { get; set; }
    }

}